import Vue from "vue";
import Router from "vue-router";
import Login from "./views/Login.vue";
import Home from "./views/Home.vue";
import Welcome from "./views/Welcome.vue";
import User from "./views/user/User.vue";
Vue.use(Router);

var router = new Router({
  routes: [
    {
      path: "/",
      redirect: "/welcome"
    },
    {
      path: "/login",
      component: Login
    },
    {
      path: "/home",
      component: Home,
      redirect: "/welcome",
      children: [
        { path: "/home", redirect: "/welcome" },
        { path: "/welcome", component: Welcome },
        { path: "/users", component: User }
      ]
    }
  ]
});
//路由守卫设置
router.beforeEach((to, from, next) => {
  var token = window.sessionStorage.getItem("token");
  if (token === null && to.path !== "/login") {
    return next("/login");
  }
  next();
});
export default router;
